<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="top">

        </ui:define>

        <ui:define name="left">

        </ui:define>
        <ui:define name="content">


            <h:form prependId="false" id="form" >   

                <p:panel header="All Source Supply">
                    <p:dataTable value="#{rawMaterialPurchaseOrderEntityController.rmqs}" var="rmq"
                                 paginator="true" rows="30"  
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"  
                                 rowsPerPageTemplate="30,50,100">
                        <p:column sortBy="#{rmq.rawMaterial.productName}" filterBy="#{rmq.rawMaterial.productName}">  
                            <f:facet name="header">  
                                <h:outputText value="Raw Material " />  
                            </f:facet>  
                            <h:outputText value="#{rmq.rawMaterial.productName}" />  
                        </p:column>

                        <p:column filterBy="#{rmq.vendor.companyName}" sortBy="#{rmq.vendor.companyName}">
                            <f:facet name="header">
                                <h:outputText value="Supplier"/>
                            </f:facet>
                            <h:outputText value="#{rmq.vendor.companyName}"/>
                        </p:column>

                        <p:column filterBy="#{rmq.price}" sortBy="#{rmq.price}">
                            <f:facet name="header">
                                <h:outputText value="Unit Price Figure:"/>
                            </f:facet>
                            <h:outputText value="#{rmq.price}"/>
                        </p:column>

                        <p:column filterBy="#{rmq.cost}" sortBy="#{rmq.cost}">
                            <f:facet name="header">
                                <h:outputText value="Total Cost"/>
                            </f:facet>
                            <h:outputText value="#{rmq.cost}"/>
                         </p:column>                          
                      <p:column filterBy="#{rmq.vendor.star}" sortBy="#{rmq.vendor.star}">
                            <f:facet name="header">
                                <h:outputText value="Vendor point:"/>
                            </f:facet>
                            <h:outputText value="#{rmq.vendor.star}"/>
                        </p:column >
                         <p:column >
                            <f:facet name="header">
                                <h:outputText value="For quotation that has deadline"/>
                            </f:facet>
                            <h:outputText value="#{rmq.validity}">
                                <f:convertDateTime pattern="dd/MM/yyyy" />
                            </h:outputText>
                        </p:column>
                        <p:column style="width:32px"> 
                            <f:facet name="header">
                                <h:outputText value="Add"/>
                            </f:facet>
                            <p:commandButton value="Add" update="books msgs @parent" process="@this" >

                                <f:setPropertyActionListener value="#{rmq}"  
                                                             target="#{rawMaterialPurchaseOrderEntityController.selectedRmq}" />
                                <p:collector value="#{rawMaterialPurchaseOrderEntityController.selectedRmq}"
                                             addTo="#{rawMaterialPurchaseOrderEntityController.rmqPurchaseList}" />
                            </p:commandButton>  
                        </p:column> 
                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <p:commandButton image="ui-icon ui-icon-search" update="display" oncomplete="customerDialog.show()">
                                <f:setPropertyActionListener value="#{rmq}"  
                                                             target="#{rawMaterialPurchaseOrderEntityController.selectedRmq}" /> 
                            </p:commandButton>
                        </p:column>

                    </p:dataTable>

                </p:panel>
                <p:separator /> 

                <p:panel header="Choosen vendor:">
                    <p:outputPanel id="books">  
                        <p:dataTable value="#{rawMaterialPurchaseOrderEntityController.rmqPurchaseList}" var="pur">  

                            <p:column>  
                                <f:facet name="header">  
                                    <h:outputText value="Raw Material" />  
                                </f:facet>  
                                <h:outputText value="#{pur.rawMaterial.productName}" />  
                            </p:column>  

                            <p:column>  
                                <f:facet name="header">  
                                    <h:outputText value="Supplier" />  
                                </f:facet>  
                                <h:outputText value="#{pur.vendor.companyName}" />  
                            </p:column>  
                            <p:column>  
                                <f:facet name="header">  
                                    <h:outputText value="Unit Price Figure:" />  
                                </f:facet>  
                                <h:outputText value="#{pur.price}" />  
                            </p:column>  
                             <p:column filterBy="#{pur.cost}" sortBy="#{pur.cost}">
                            <f:facet name="header">
                                <h:outputText value="Total Cost"/>
                            </f:facet>
                            <h:outputText value="#{pur.cost}"/>
                        </p:column>

                            <p:column>  
                                <f:facet name="header">  
                                    <h:outputText value="Operations" />  
                                </f:facet>  
                                <p:commandButton value="Remove" update="books msgs @parent" >
                                    <f:setPropertyActionListener value="#{pur}"  
                                                                 target="#{rawMaterialPurchaseOrderEntityController.selectedRmq}" /> 
                                    <p:collector value="#{rawMaterialPurchaseOrderEntityController.selectedRmq}"  
                                                 removeFrom="#{rawMaterialPurchaseOrderEntityController.rmqPurchaseList}" />  
                                </p:commandButton>  
                            </p:column>  
                    

                        </p:dataTable>  
                    </p:outputPanel>  
                </p:panel>

                <p:dialog header="Quotation Information:" widgetVar="customerDialog" resizable="false"  
                          width="325" showEffect="explode" hideEffect="explode">  

                    <h:panelGrid id="display" columns="2" cellpadding="4">  
                        <h:outputText value="Vendor:"/>
                        <h:outputText value="#{rawMaterialPurchaseOrderEntityController.selectedRmq.vendor.companyName}"/>

                        <h:outputText value="Product:"/>
                        <h:outputText value="#{rawMaterialPurchaseOrderEntityController.selectedRmq.rawMaterial.productName}"/>     
                        <h:outputText value="Price:"/>
                        <h:outputText value="#{rawMaterialPurchaseOrderEntityController.selectedRmq.price}"/>
                        <h:outputText value="Quantity:"/>
                        <h:outputText value="#{rawMaterialPurchaseOrderEntityController.selectedRmq.quantity}"/>
                        <h:outputText value="Total cost:"/>
                        <h:outputText value="#{rawMaterialPurchaseOrderEntityController.selectedRmq.cost}"/>
                        <h:outputText value="Vendor Note:"/>
                        <h:outputText value="#{rawMaterialPurchaseOrderEntityController.selectedRmq.note}"/>
                    </h:panelGrid>  
                </p:dialog>  

                <br/>
                <p:commandButton ajax="false" value="Confirm" onclick="confirmation.show()" type="button" update ="growl"/>    
                <p:confirmDialog message="Are you sure ?"  
                showEffect="bounce" hideEffect="explode"  
                header="Purchase initiating" severity="alert" widgetVar="confirmation">  
                  
        <p:commandButton value="Yes Sure" update="growl" oncomplete="confirmation.hide()"  
                    actionListener="#{rawMaterialPurchaseOrderEntityController.createPurchase}" />  
        <p:commandButton value="Not Yet" onclick="confirmation.hide()" type="button" />   
                  
    </p:confirmDialog>  
            </h:form>    
        </ui:define>
    </ui:composition>



</html>